package MyDynamicProxyTest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory implements InvocationHandler {

    private Object obj;

    public Object CreateProxy(Object obj){
        this.obj=obj;

        ClassLoader classLoader = ProxyFactory.class.getClassLoader();

        Class[] clazz = obj.getClass().getInterfaces();

        return Proxy.newProxyInstance(classLoader,clazz,this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("fighting！！！");
        Object obj1 = method.invoke(obj, args);
        System.out.println("earn money");

        return obj1;
    }
}
